home *** CD-ROM | disk | FTP | other *** search
/ Champak 62 / Volume 62 - JOGO DISK .iso / Games / penguin_dinner.swf / scripts / __Packages / com / potapenko / util / MovieClipUtil.as
Text File  |  2008-03-17  |  8KB  |  321 lines

  1. class com.potapenko.util.MovieClipUtil extends Object
  2. {
  3.    function MovieClipUtil(movie)
  4.    {
  5.       super();
  6.       this.movie = movie;
  7.    }
  8.    function moveTo(x, y)
  9.    {
  10.       this.movie._x = x;
  11.       this.movie._y = y;
  12.       return this;
  13.    }
  14.    function moveBy(xo, yo)
  15.    {
  16.       this.movie._x += xo;
  17.       this.movie._y += yo;
  18.       return this;
  19.    }
  20.    function size(w, h)
  21.    {
  22.       if(w != null && w != 0)
  23.       {
  24.          this.movie._width = w;
  25.       }
  26.       if(h != null && h != 0)
  27.       {
  28.          this.movie._height = h;
  29.       }
  30.       return this;
  31.    }
  32.    function scale(s)
  33.    {
  34.       this.movie._xscale = this.movie._yscale = s;
  35.       return this;
  36.    }
  37.    function scaleTo(xscale, yscale)
  38.    {
  39.       if(xscale != null && xscale != 0)
  40.       {
  41.          this.movie._xscale = xscale;
  42.       }
  43.       if(yscale != null && yscale != 0)
  44.       {
  45.          this.movie._yscale = yscale;
  46.       }
  47.       return this;
  48.    }
  49.    function scaleBy(sc)
  50.    {
  51.       this.movie._xscale *= sc;
  52.       this.movie._yscale *= sc;
  53.       return this;
  54.    }
  55.    function rotateBy(ri)
  56.    {
  57.       this.movie._rotation += ri;
  58.       return this;
  59.    }
  60.    function hide()
  61.    {
  62.       this.movie._visible = false;
  63.       return this;
  64.    }
  65.    function show()
  66.    {
  67.       this.movie._visible = true;
  68.       return this;
  69.    }
  70.    function visInvert()
  71.    {
  72.       this.movie._visible = !this.movie._visible;
  73.       return this;
  74.    }
  75.    function flipV()
  76.    {
  77.       this.movie._xscale *= -1;
  78.       return this;
  79.    }
  80.    function flipH()
  81.    {
  82.       this.movie._yscale *= -1;
  83.       return this;
  84.    }
  85.    function playOffset(po)
  86.    {
  87.       this.movie.gotoAndPlay(this.movie._currentframe + po);
  88.       return this;
  89.    }
  90.    function childs()
  91.    {
  92.       var _loc2_ = new Array();
  93.       for(var _loc3_ in this.movie)
  94.       {
  95.          if(typeof this.movie[_loc3_] == "movieclip" && this.movie[_loc3_]._parent == this.movie)
  96.          {
  97.             _loc2_.push(this.movie[_loc3_]);
  98.          }
  99.       }
  100.       return _loc2_;
  101.    }
  102.    function getAllChilds()
  103.    {
  104.       var _loc5_ = arguments[0];
  105.       var _loc7_ = arguments[1];
  106.       var _loc9_ = false;
  107.       if(_loc5_ == null)
  108.       {
  109.          _loc5_ = new Array();
  110.          _loc9_ = true;
  111.       }
  112.       else
  113.       {
  114.          _loc5_.push(this);
  115.       }
  116.       this.movie.__tested_marker = true;
  117.       var _loc3_ = undefined;
  118.       var _loc6_ = undefined;
  119.       for(var _loc8_ in this.movie)
  120.       {
  121.          _loc3_ = this.movie[_loc8_];
  122.          if(typeof _loc3_ == "movieclip" && _loc3_.__tested_marker == undefined && _loc3_._parent == this.movie)
  123.          {
  124.             _loc6_ = new com.potapenko.util.MovieClipUtil(_loc3_);
  125.             _loc6_.getAllChilds(_loc5_,_loc7_);
  126.          }
  127.       }
  128.       if(_loc9_)
  129.       {
  130.          var _loc4_ = 0;
  131.          while(_loc4_ < _loc5_.length)
  132.          {
  133.             delete _loc5_[_loc4_].__tested_marker;
  134.             _loc4_ = _loc4_ + 1;
  135.          }
  136.       }
  137.       return _loc5_;
  138.    }
  139.    function copy(fromClip, paramArray)
  140.    {
  141.       if(paramArray == null)
  142.       {
  143.          paramArray = new Array("_width","_height","_x","_y","_alpha","_rotation");
  144.       }
  145.       var _loc5_ = fromClip._rotation;
  146.       fromClip._rotation = 0;
  147.       var _loc6_ = this.movie._rotation;
  148.       this.movie._rotation = 0;
  149.       var _loc2_ = 0;
  150.       while(_loc2_ < paramArray.length)
  151.       {
  152.          this.movie[paramArray[_loc2_]] = fromClip[paramArray[_loc2_]];
  153.          _loc2_ = _loc2_ + 1;
  154.       }
  155.       fromClip._rotation = _loc5_;
  156.       this.movie._rotation = _loc5_;
  157.       return this;
  158.    }
  159.    function copyColor(fromClip)
  160.    {
  161.       new Color(this.movie).setTransform(new Color(fromClip).getTransform());
  162.       return this;
  163.    }
  164.    function top()
  165.    {
  166.       if(this.movie._parent != _root)
  167.       {
  168.          return this.movie._parent.top();
  169.       }
  170.       return this.movie;
  171.    }
  172.    function newSound(id, volume, loop)
  173.    {
  174.       this.movie.mySound = new Sound();
  175.       this.movie.mySound.attachSound(id);
  176.       this.movie.mySound.setVolume(volume || 100);
  177.       this.movie.mySound.start(0,loop || 1);
  178.       return this;
  179.    }
  180.    function stopSound(id, volume, loop)
  181.    {
  182.       this.movie.mySound.stop();
  183.       return this;
  184.    }
  185.    function localToLocal(toMcCoordinats, point)
  186.    {
  187.       this.movie.localToGlobal(point);
  188.       toMcCoordinats.globalToLocal(point);
  189.    }
  190.    function align(fromClip, ignoreFromBounds, ignoreMovieBounds)
  191.    {
  192.       if(fromClip == undefined)
  193.       {
  194.          fromClip = this.movie._parent;
  195.       }
  196.       var _loc8_ = fromClip.getBounds(_root);
  197.       var _loc7_ = this.movie.getBounds(_root);
  198.       var _loc5_ = {x:(_loc8_.xMin + _loc8_.xMax) / 2,y:(_loc8_.yMin + _loc8_.yMax) / 2};
  199.       if(fromClip._width == 0 || ignoreFromBounds == true)
  200.       {
  201.          var _loc9_ = {x:fromClip._x,y:10};
  202.          fromClip._parent.localToGlobal(_loc9_);
  203.          _loc5_.x = _loc9_.x;
  204.       }
  205.       if(fromClip._height == 0 || ignoreFromBounds == true)
  206.       {
  207.          _loc9_ = {x:10,y:fromClip._y};
  208.          fromClip._parent.localToGlobal(_loc9_);
  209.          _loc5_.y = _loc9_.y;
  210.       }
  211.       var _loc6_ = {x:(_loc7_.xMin + _loc7_.xMax) / 2,y:(_loc7_.yMin + _loc7_.yMax) / 2};
  212.       if(this.movie._width == 0 || ignoreMovieBounds == true)
  213.       {
  214.          _loc9_ = {x:this.movie._x,y:10};
  215.          fromClip._parent.localToGlobal(_loc9_);
  216.          _loc6_.x = _loc9_.x;
  217.       }
  218.       if(this.movie._height == 0 || ignoreMovieBounds == true)
  219.       {
  220.          _loc9_ = {x:10,y:this.movie._y};
  221.          fromClip._parent.localToGlobal(_loc9_);
  222.          _loc6_.y = _loc9_.y;
  223.       }
  224.       this.movie._parent.globalToLocal(_loc5_);
  225.       this.movie._parent.globalToLocal(_loc6_);
  226.       if(arguments[1] != "v")
  227.       {
  228.          this.movie._x += _loc5_.x - _loc6_.x;
  229.       }
  230.       if(arguments[1] != "h")
  231.       {
  232.          this.movie._y += _loc5_.y - _loc6_.y;
  233.       }
  234.       return this;
  235.    }
  236.    function alignH(fromClip)
  237.    {
  238.       this.movie.align(fromClip,"h");
  239.       return this;
  240.    }
  241.    function alignV(fromClip)
  242.    {
  243.       this.movie.align(fromClip,"v");
  244.       return this;
  245.    }
  246.    function createRound(name, depth, radius, color)
  247.    {
  248.       var _loc2_ = this.movie.createEmptyMovieClip(name,depth);
  249.       radius = radius / 2 || 2;
  250.       _loc2_.lineStyle(radius,color || 0,100);
  251.       _loc2_.lineTo(0,0.15);
  252.       return _loc2_;
  253.    }
  254.    function createSqv(name, depth, width, color, center)
  255.    {
  256.       if(depth == undefined)
  257.       {
  258.          depth = 2123;
  259.       }
  260.       if(width == undefined)
  261.       {
  262.          width = 12;
  263.       }
  264.       if(center == undefined)
  265.       {
  266.          center = true;
  267.       }
  268.       var _loc3_ = this.movie.createEmptyMovieClip(name,depth);
  269.       var _loc2_ = 0;
  270.       if(center)
  271.       {
  272.          _loc2_ = (- width) / 2;
  273.       }
  274.       _loc3_.moveTo(_loc2_,_loc2_);
  275.       _loc3_.beginFill(color || 0);
  276.       _loc3_.lineTo(width + _loc2_,_loc2_);
  277.       _loc3_.lineTo(width + _loc2_,width + _loc2_);
  278.       _loc3_.lineTo(_loc2_,width + _loc2_);
  279.       _loc3_.lineTo(_loc2_,_loc2_);
  280.       _loc3_.endFill();
  281.       return _loc3_;
  282.    }
  283.    function pixelatePosition()
  284.    {
  285.       var _loc2_ = this.movie.localToGlobal({x:this.movie._x,y:this.movie._y});
  286.       this.movie._x -= _loc2_.x % 1;
  287.       this.movie._y -= _loc2_.y % 1;
  288.       return this;
  289.    }
  290.    function animToPlace(startA, finishA, steps, currStep, xy)
  291.    {
  292.       this.movie[xy] = this.inOut(startA,finishA,steps,currStep);
  293.       return this;
  294.    }
  295.    function inOut(startA, finishA, steps, currStep)
  296.    {
  297.       if(currStep >= steps)
  298.       {
  299.          return finishA;
  300.       }
  301.       if(currStep <= 0)
  302.       {
  303.          return startA;
  304.       }
  305.       return startA + (finishA - startA) * this.ease(steps * 2,currStep);
  306.    }
  307.    function ease(steps, curStep)
  308.    {
  309.       if(steps <= curStep)
  310.       {
  311.          return 0;
  312.       }
  313.       if(steps / 2 == curStep)
  314.       {
  315.          return 1;
  316.       }
  317.       var _loc1_ = Math.sin(curStep / steps * 180 * 3.141592653589793 / 180);
  318.       return _loc1_ * _loc1_ * _loc1_;
  319.    }
  320. }
  321.